"""
    @Author: 张晟煜
    @Description:创建僵尸Zombie类、以及方法Creat_Zombie
    @Date:
    @Version:
"""

import random

# 更改1：添加全局变量
# 全局僵尸击杀数
zombie_kill = 0
money = 0
"""
    僵尸类，包括僵尸生产频率
    
"""
class Zombie:
    def __init__(self):
        self.Zombie_num = 0  # 僵尸生成频率
        self.Zombie_Location_List = []  # 僵尸列表
        self.x = 1000
        self.life = 3  # 僵尸初始生命值
        self.speed = 1  # 僵尸初始移动速度
        self.Zombie_number = 200  # 僵尸出现变量
        self.Zombie_Go_ballistic_time = 0  # 暴走初始时间
        self.Zombie_Go_ballistic_time_max = 2000  # 僵尸暴走时间

    """
    创建僵尸方法Creat_Zombie
    1、僵尸生成频率判断
    2、僵尸移动判断
    3、暴走判断
    """
    def Creat_Zombie(self):#创建僵尸的坐标

        if self.Zombie_num>=self.Zombie_number and self.Zombie_num%self.Zombie_number==0:
            #Zombie_Location=[[x坐标，y坐标，生命值，初始行动状态（步行）]]
            Zombie_Location = [[self.x,75,self.life,0],[self.x,175,self.life,0],[self.x,275,self.life,0],[self.x,375,self.life,0],[self.x,475,self.life,0]]#僵尸生成位置
            rand=random.randint(0,4)
            self.Zombie_Location_List.append(Zombie_Location[rand])
            for i in self.Zombie_Location_List:
                if i[0]<=-50:#当僵尸坐标为-50时，删除僵尸
                    self.Zombie_Location_List.pop(self.Zombie_Location_List.index(i))
                    continue
            self.Zombie_num=0
            return self.Zombie_Location_List
        if self.Zombie_Location_List!=[]:#僵尸移动
            for i in self.Zombie_Location_List:
                i[0]-=self.speed
                if i[2] <= 0:  # 当僵尸生命值为0时，更新僵尸死亡数并从列表中移除
                    # 更改2：调用添加击杀数和金币数
                    self.update_zombie_kill()  # 更新僵尸击杀数
                    self.Zombie_Location_List.remove(i)
        self.Zombie_num+=1
        self.Zombie_Go_ballistic_time+=1
        if self.Zombie_Go_ballistic_time>self.Zombie_Go_ballistic_time_max:#暴走之后更新僵尸属性
            self.speed=2
            self.life=15
            self.Zombie_number=30
        return self.Zombie_Location_List
    def update_zombie_kill(self):
        global zombie_kill
        global money
        zombie_kill += 1
        money = 100 * zombie_kill
        print("Zombie killed: " + str(zombie_kill))
        print("money:"+str(money))